<!-------- USER ADMIN -------->
<cfoutput>
	<cfif flashKeyExists("admin")>#flashMessages(key="admin", class="alert-message success")#<cfset flashClear()></cfif>	
	<div id="userSettings" style="width: 900px; margin: 0 auto;">
		<form id="Users" action="#URLFor(controller='user', action='updateUser')#">			
			<table class="forms" width="100%">
				<thead>
					<tr>
						<cfloop list="First Name,Last Name,Primary Phone,Secondary Phone,E-Mail,User Type,add" index="ColumnHeader">
							<cfif ColumnHeader IS "add">
								<th class="transparent">
									<div class="btn-group" style="margin: 9px 0;">
										<button class="btn btn-info btn-single addButton" title="Add User">
											<i class="icon-plus icon-white"></i>
										</button>
									</div>
								</th>
							<cfelse>
								<th class="title">#ColumnHeader#</th>
							</cfif>
						</cfloop>
					</tr>
				</thead>
				<tbody>
					<cfloop query="users">
						<tr class="row#CurrentRow MOD 2# currentUsers">
							<td valign="middle">
									<div class="user">#firstName#</div>
									<div class="user-edit">#textFieldTag(id="update-#id#-firstName", name="update[#id#][firstName]", class="validate[required] normal", value="#firstName#", maxlength="20")#</div>
							</td>
							<td valign="middle">
									<div class="user">#lastName#</div>
									<div class="user-edit">#textFieldTag(id="update-#id#-lastName", name="update[#id#][lastName]", class="validate[required] normal", value="#lastName#", maxlength="20")#</div>
							</td>
							<td valign="middle">
								<div class="user">#mainPhoneNumber#</div>
								<div class="user-edit">
									#textFieldTag(id="update-#id#-mainPhone-1", name="update[#id#][mainPhone]", class="validate[required,custom[number]] phone-3 numeric", prepend="<strong>( </strong>", value="#Mid(mainPhone, 1, 3)#", maxlength="3")#
									#textFieldTag(id="update-#id#-mainPhone-2", name="update[#id#][mainPhone]", class="validate[required,custom[number]] phone-3 numeric", prepend="<strong> ) </strong>", value="#Mid(mainPhone, 4, 3)#", maxlength="3")#
									#textFieldTag(id="update-#id#-mainPhone-3", name="update[#id#][mainPhone]", class="validate[required,custom[number]] phone-4 numeric", prepend="<strong> - </strong>", value="#Mid(mainPhone, 7, 4)#", maxlength="4")#
								</div>
							</td>
							<td valign="middle">
								<div class="user">#secondaryPhoneNumber#</div>
								<div class="user-edit">
									#textFieldTag(id="update-#id#-secondaryPhone-1", name="update[#id#][secondaryPhone]", class="validate[custom[number]] phone-3 numeric", prepend="<strong>( </strong>", value="#Mid(secondaryPhone, 1, 3)#", maxlength="3")#
									#textFieldTag(id="update-#id#-secondaryPhone-2", name="update[#id#][secondaryPhone]", class="validate[custom[number]] phone-3 numeric", prepend="<strong> ) </strong>", value="#Mid(secondaryPhone, 4, 3)#", maxlength="3")#
									#textFieldTag(id="update-#id#-secondaryPhone-3", name="update[#id#][secondaryPhone]", class="validate[custom[number]] phone-4 numeric", prepend="<strong> - </strong>", value="#Mid(secondaryPhone, 7, 4)#", maxlength="4")#
								</div>
							</td>
							<td valign="middle">
								<div class="user">#email#</div>
								<div class="user-edit email">#textFieldTag(id="update-#id#-email", name="update[#id#][email]", class="validate[required,custom[email]] normal1", value="#email#", maxlength="30")#</div>
							</td>
							<td  style="white-space: nowrap;"  valign="middle">
								<div class="userType">#userType#</div>
								<div class="userType-edit radiobutton" default-userType="#userTypeID#">
									#radioButtonTag(id="update-#id#-userTypeID-3", class="validate[required]", name="update[#id#][userTypeID]", value="3", label="Doctor ")#
									#radioButtonTag(id="update-#id#-userTypeID-2", class="validate[required]", name="update[#id#][userTypeID]", value="2", label="User ")#
									#radioButtonTag(id="update-#id#-userTypeID-1", class="validate[required]", name="update[#id#][userTypeID]", value="1", label="Admin ")#
								</div>
							</td>
							<td class="transparent left" valign="middle">
								<div class="btn-group" style="margin: 9px 0;">
									<button class="btn btn-inverse btn-single editButton" title="Edit User">
										<i class="icon-pencil icon-white"></i>
									</button>
									<button class="btn btn-danger btn-single deleteButton" delete-url="#URLFor(controller='user', action='deleteUser', key=id)#" title="Delete User">
										<i class="icon-trash icon-white"></i>
									</button>
								</div>
							</td>
						</tr>		
					</cfloop>
				</tbody>
			</table>
		</form>
	</div>
	<cfset userRow = "#dspAdminUserTR()#">
	<script type="text/javascript">#toScript(userRow, "var $row")#	</script>
</cfoutput>
<script  type="text/javascript">
	$('div.userType-edit').each(function() {
		$value = $(this).attr('default-userType');
		$(this).find('input[value="' +$value + '"]').attr("checked", true);
		$(this).hide();
	});

	$('div.user').next().hide();
	
	//--> Form Helpers with jQuery.Tipsy <--//
	$('.editButton').tipsy({
		gravity: 'w',
		fade: true,
		live: true
	}).on("click", function() {
			$parent = $(this).parent().parent().parent();
			$parent.find('div.user-edit').show();
			$parent.find('div.user').hide();
			
			$parent.find('div.userType').hide().next().show();
		});

	$('.addButton, .deleteButton').tipsy({
		gravity: 'w',
		fade: true,
		live: true
	})

	$('input').tipsy({
		gravity: 's',
		fade: true,
		live: true	
	});

	//--> Data Validation with jQuery.ValidationEngine
	$('form').validationEngine({
		promptPosition: "bottomLeft"
	});

	//--> Admin Maintenance Interactions
	var intRow = 0;

	$('.addButton')
		.on("click", function() {
		intRow++;
		$('tbody').prepend($row.replace(/\[\]/g, intRow));
	});

	$('.deleteButton').on("click", function() {
		intRow--;
		$(this).parent().parent().remove();	
		$dialog.dialog("close");
		
		$(".tipsy-w").remove();

		if($(this).attr('delete-url') != "") {
			$.ajax({
				url: $(this).attr('delete-url'),
				complete: function() {
					$('#userButton').click();
					
				}
			});	
		}
		return false;
	});
</script>